-- demo_madang.sql ---------------------------------------- DROP TABLE book CASCADE CONSTRAINTS; DROP TABLE customer CASCADE CONSTRAINTS; DROP TABLE orders CASCADE CONSTRAINTS; purge recyclebin; CREATE TABLE book ( bookid NUMBER(2) NOT NULL, bookname VARCHAR2(40), publisher VARCHAR2(40), price NUMBER(8) ); ALTER TABLE book ADD CONSTRAINT book_pk PRIMARY KEY ( bookid ); CREATE TABLE customer ( custid NUMBER(2) NOT NULL, name VARCHAR2(40), address VARCHAR2(50), phone VARCHAR2(20) ); ALTER TABLE customer ADD CONSTRAINT customer_pk PRIMARY KEY ( custid ); CREATE TABLE orders ( orderid NUMBER(2) NOT NULL, custid NUMBER(2) NOT NULL, bookid NUMBER(2) NOT NULL, saleprice NUMBER(8), orderdate DATE ); ALTER TABLE orders ADD CONSTRAINT orders_pk PRIMARY KEY ( orderid ); ALTER TABLE orders ADD CONSTRAINT relation_1 FOREIGN KEY ( bookid ) REFERENCES book ( bookid ); ALTER TABLE orders ADD CONSTRAINT relation_2 FOREIGN KEY ( custid ) REFERENCES customer ( custid ); select * from tab; -------------------------------------- --book ---------------------------------------------------------------------------- insert into BOOK values( 1,'Ã౸ÀÇ ¿ª»ç' ,'±Â½ºÆ÷Ã÷' , 7000); insert into BOOK values( 2,'Ã౸¾Æ´Â ¿©ÀÚ' ,'³ª¹«¼ö' , 13000); insert into BOOK values( 3,'Ã౸ÀÇ ÀÌÇØ' ,'´ëÇѹ̵ð¾î' , 22000); insert into BOOK values( 4,'°ñÇÁ ¹ÙÀ̺í' ,'´ëÇѹ̵ð¾î' , 35000); insert into BOOK values( 5,'ÇÇ°Ü ±³º»' ,'±Â½ºÆ÷Ã÷' , 8000); insert into BOOK values( 6,'¿ªµµ ´Ü°èº°±â¼ú' ,'±Â½ºÆ÷Ã÷' , 6000); insert into BOOK values( 7,'¾ß±¸ÀÇ Ãß¾ï' ,'ÀÌ»ó¹Ìµð¾î' , 20000); insert into BOOK values( 8,'¾ß±¸¸¦ ºÎŹÇØ' ,'ÀÌ»ó¹Ìµð¾î' , 13000); insert into BOOK values( 9,'¿Ã¸²ÇÈ À̾߱â' ,'»ï¼º´ç' , 7500); insert into BOOK values(10,'Olympic Champions' ,'Pearson' , 13000); commit; select * from BOOK ; --CUSTOMER ------------------------------------------------------------------------------ insert into CUSTOMER values( 1,'¹ÚÁö¼º' ,'¿µ±¹ ¸Çü½ºÅ¸' ,'000-5000-0001' ); insert into CUSTOMER values( 2,'±è¿¬¾Æ' ,'´ëÇѹα¹ ¼­¿ï' ,'000-6000-0001' ); insert into CUSTOMER values( 3,'Àå¹Ì¶õ' ,'´ëÇѹα¹ °­¿øµµ' ,'000-7000-0001' ); insert into CUSTOMER values( 4,'Ã߽żö' ,'¹Ì±¹ Ŭ¸®ºí·£µå' ,'000-8000-0001' ); insert into CUSTOMER values( 5,'¹Ú¼¼¸®' ,'´ëÇѹα¹ ´ëÀü' ,'' ); commit; select * from CUSTOMER ; --ORDERS -- ÁÖ¹®(Orders) Å×À̺íÀÇ Ã¥°ªÀº ÇÒÀÎ ÆǸŸ¦ °¡Á¤ÇÔ ----------------------------------------------------------- insert into ORDERS values( 1, 1, 1, 6000,'01-JUL-14'); insert into ORDERS values( 2, 1, 3, 21000,'03-JUL-14'); insert into ORDERS values( 3, 2, 5, 8000,'03-JUL-14'); insert into ORDERS values( 4, 3, 6, 6000,'04-JUL-14'); insert into ORDERS values( 5, 4, 7, 20000,'05-JUL-14'); insert into ORDERS values( 6, 1, 2, 12000,'07-JUL-14'); insert into ORDERS values( 7, 4, 8, 13000,'07-JUL-14'); insert into ORDERS values( 8, 3, 10, 12000,'08-JUL-14'); insert into ORDERS values( 9, 2, 10, 7000,'09-JUL-14'); insert into ORDERS values( 10, 3, 8, 13000,'10-JUL-14'); commit; select * from ORDERS ; ---------------------------------------- -- 3Àå¿¡¼­ »ç¿ëµÇ´Â Imported_book Å×À̺í CREATE TABLE Imported_Book ( bookid NUMBER , bookname VARCHAR(40), publisher VARCHAR(40), price NUMBER(8) ); INSERT INTO Imported_Book VALUES(21, 'Zen Golf' , 'Pearson' , 12000); INSERT INTO Imported_Book VALUES(22, 'Soccer Skills', 'Human Kinetics', 15000); COMMIT; select * from tab;